import java.util.Arrays;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-03-24
 * Time: 18:13
 */
public class test5 {
    /**
     * 1000个整数，数值的范围是[0,999]，有且只有2个相同的数，请编写程序找出来
     */

    // 1.排序，相邻之间找出相同的数
    public static void main(String[] args) {
        int[] numArr = {};

        Arrays.sort(numArr);
        for(int i=0;i<numArr.length;i++){
            if(numArr[i] == numArr[i+1]){
                System.out.println(numArr[i]);
                break;
            }
        }
    }

    // 2.哈希Set
    public static void main1(String[] args) {
        int[] numArr = {};

        HashSet<Integer> set = new HashSet<>();
        for(int i=0;i< numArr.length;i++){
            if(!set.add(numArr[i])){
                System.out.println(numArr[i]);
                break;
            }
        }
    }
}
